package com.xy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xy.constants.CertificateTypeKey;
import com.xy.dto.ExhibitionUserDTO;
import com.xy.entity.CertificateApplyEntity;
import com.xy.excel.*;
import com.xy.service.ExhibitionUserService;
import com.xy.utils.IdCardCheckUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.support.ExcelException;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static com.xy.constants.CertificateTypeKey.PER_CERTIFICATE_TYPE;

/**
 * 展商管理
 *
 * @author BladeX
 * @since 2023-07-21
 */
@RestController
@AllArgsConstructor
@RequestMapping("/exhibitionUser")
@Api(value = "展商管理", tags = "展商管理")
@Slf4j
public class ExhibitionUserController extends BladeController {

	private final ExhibitionUserService exhibitionUserService;
	/**
	 * 展商管理 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入ExhibitionUserDTO")
	public R save(@Valid @RequestBody ExhibitionUserDTO exhibitionUser) {

		return R.status(exhibitionUserService.save(exhibitionUser));
	}

	/**
	 * 展商管理 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入ExhibitionUserDTO")
	public R update(@Valid @RequestBody ExhibitionUserDTO exhibitionUser) {

		return R.status(exhibitionUserService.update(exhibitionUser));
	}
	/**
	 * 展商管理 导入
	 */
	@ApiOperation(value = "导入展商管理", notes = "传入excel")
	@ApiOperationSupport(order = 24)
	@PostMapping("/per/import")
	public R<String> perImport(MultipartFile file) {
		ExhibitionUserImporter perImport = new ExhibitionUserImporter(exhibitionUserService, false, PER_CERTIFICATE_TYPE);
		ExcelUtil.save(file, perImport, ExhibitionUserExcel.class);
		return R.success("操作成功");
	}
	@GetMapping("/car/temp")
	@ApiOperationSupport(order = 18)
	@ApiOperation(value = "展商管理导入模板")
	public void carExporTemp(HttpServletResponse response) {
		//VehicleExcel vehicleExcel = new VehicleExcel();
		//vehicleExcel.setLicensePlate("浙A:12323");
		//vehicleExcel.setLinkman("张三");
		//vehicleExcel.setOrgName("开发部");
		//vehicleExcel.setNumberOfSeats(5);
		//vehicleExcel.setPhone("18611111111");
		//vehicleExcel.setVehicleModel("SUV");
		List<ExhibitionUserExcel> list = new ArrayList<>();
		ExcelUtil.export(response, "展商管理导入模板" + DateUtil.time(), "展商管理导入模板", list, ExhibitionUserExcel.class);
	}


}
